<html>
<head><meta charset="utf-8"><title>weird MIR name resolution? · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/weird.20MIR.20name.20resolution.3F.html">weird MIR name resolution?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="226418053"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/weird%20MIR%20name%20resolution%3F/near/226418053" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bstrie <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/weird.20MIR.20name.20resolution.3F.html#226418053">(Feb 15 2021 at 18:41)</a>:</h4>
<p>Background for the first weirdness: the lang item for <code>drop_in_place</code> is <code>ptr::drop_in_place</code>. For historical reasons there exists <code>intrinsics::drop_in_place</code> as a deprecated re-export of <code>ptr::drop_in_place</code>. AFAICT there should be no reason <code>intrinsics::drop_in_place</code> to be emitted anywhere in codegen, since codegen should always be using the lang item. And yet <a href="https://github.com/rust-lang/rust/blob/d1206f950ffb76c76e1b74a19ae33c2b7d949454/src/test/mir-opt/inline/inline-shims.rs">this mir-opt test</a> produces <a href="https://github.com/rust-lang/rust/blob/d1206f950ffb76c76e1b74a19ae33c2b7d949454/src/test/mir-opt/inline/inline_shims.drop.Inline.diff#L27">this output</a>, which clearly refers to <code>intrinsics::drop_in_place</code>.</p>
<p>Background for the second weirdness: because <code>#[rustc_deprecated]</code> secretly doesn't work when applied to re-exports, <code>intrinsics::drop_in_place</code> was never actually deprecated. So in <a href="https://github.com/rust-lang/rust/pull/82122">https://github.com/rust-lang/rust/pull/82122</a> I turned <code>intrinsics::drop_in_place</code> from a re-export into a wrapper over <code>ptr::drop_in_place</code>. And now, without any other changes, that mir-opt test does suddenly start referring to <code>ptr::drop_in_place</code> <a href="https://github.com/rust-lang/rust/pull/82122/files#diff-38ba3313fde9bdfe9b195b4d2099b98f9f359242f93841a65801e1d52799bf47R27">in its output</a>.</p>
<p>So the good news is that the two weirdnesses balance each other out, but I'm worried that it might be masking an actual bug. Any thoughts?</p>



<a name="226471528"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/weird%20MIR%20name%20resolution%3F/near/226471528" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/weird.20MIR.20name.20resolution.3F.html#226471528">(Feb 16 2021 at 04:47)</a>:</h4>
<p>I am able to reproduce the first weirdness with this code (<a href="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=c95aa4ceae9ac88d7c814571e69aef86">playground</a>):</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">fn</span> <span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">unsafe</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">std</span>::<span class="n">ptr</span>::<span class="n">drop_in_place</span><span class="p">(</span><span class="o">&amp;</span><span class="k">mut</span><span class="w"> </span><span class="mi">1</span><span class="p">);</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>To be clear, name resolution happens way before MIR building. I suspect the bug occurs somewhere between name resolution and MIR building since it seems like a pretty extreme and bizarre bug to occur in name resolution.</p>



<a name="226549519"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/weird%20MIR%20name%20resolution%3F/near/226549519" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bstrie <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/weird.20MIR.20name.20resolution.3F.html#226549519">(Feb 16 2021 at 17:49)</a>:</h4>
<p>I've filed an issue for this at <a href="https://github.com/rust-lang/rust/issues/82189">https://github.com/rust-lang/rust/issues/82189</a></p>



<a name="226552373"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/weird%20MIR%20name%20resolution%3F/near/226552373" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/weird.20MIR.20name.20resolution.3F.html#226552373">(Feb 16 2021 at 18:09)</a>:</h4>
<p>I strongly suspect this is going to be a cosmetic issue, possibly arising due to a particularity of how the lang item is implemented.</p>



<a name="226556445"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/weird%20MIR%20name%20resolution%3F/near/226556445" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bstrie <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/weird.20MIR.20name.20resolution.3F.html#226556445">(Feb 16 2021 at 18:37)</a>:</h4>
<p>so in the pretty-printer somewhere? that's what I was hoping, but a grep for "intrinsics::drop_in_place" didn't turn up anything useful in the compiler tree, and I'm unfamiliar with where else to start looking there</p>



<a name="226557593"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/weird%20MIR%20name%20resolution%3F/near/226557593" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/weird.20MIR.20name.20resolution.3F.html#226557593">(Feb 16 2021 at 18:47)</a>:</h4>
<p>well, not that way. More plausible explanation would be that asking for the implementation of the lang item in compiler gives the intrinsic's defid. Which is a valid implementation, especially because nothing after HAIR cares about deprecations etc.</p>



<a name="226557636"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/weird%20MIR%20name%20resolution%3F/near/226557636" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/weird.20MIR.20name.20resolution.3F.html#226557636">(Feb 16 2021 at 18:47)</a>:</h4>
<p>I can see things breaking if the intrinsic itself is _removed_. But deprecation will not change anything.</p>



<a name="226557727"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/weird%20MIR%20name%20resolution%3F/near/226557727" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/weird.20MIR.20name.20resolution.3F.html#226557727">(Feb 16 2021 at 18:48)</a>:</h4>
<p>A curious thing is that if you ask <code>rustc</code> for <code>-Zdump-mir</code> it will also dump the MIR for <code>ptr::drop_in_place</code> for the given example code.</p>



<a name="226558396"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/weird%20MIR%20name%20resolution%3F/near/226558396" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tm <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/weird.20MIR.20name.20resolution.3F.html#226558396">(Feb 16 2021 at 18:53)</a>:</h4>
<p>I am vaguely aware of some code that when pretty printing paths prefers to show publicly reachable re-exports, which would be my first suspicion of what is going on here.</p>



<a name="226560529"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/weird%20MIR%20name%20resolution%3F/near/226560529" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bstrie <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/weird.20MIR.20name.20resolution.3F.html#226560529">(Feb 16 2021 at 19:09)</a>:</h4>
<p>my mild concern here is that after <a href="https://github.com/rust-lang/rust/pull/82122">https://github.com/rust-lang/rust/pull/82122</a> lands and turns the intrinsic from a re-export into a wrapper fn, that it might lead to marginally worse codegen if it's not using the lang item and instead tries to go through the wrapper</p>



<a name="226563131"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/weird%20MIR%20name%20resolution%3F/near/226563131" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tm <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/weird.20MIR.20name.20resolution.3F.html#226563131">(Feb 16 2021 at 19:26)</a>:</h4>
<p>The implementation would be in <a href="https://github.com/rust-lang/rust/blob/master/compiler/rustc_middle/src/ty/print/pretty.rs#L268">https://github.com/rust-lang/rust/blob/master/compiler/rustc_middle/src/ty/print/pretty.rs#L268</a></p>



<a name="226563382"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/weird%20MIR%20name%20resolution%3F/near/226563382" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/weird.20MIR.20name.20resolution.3F.html#226563382">(Feb 16 2021 at 19:28)</a>:</h4>
<p>Yes, the issue here is that <code>std::ptr</code> is a reexport (of <code>core::ptr</code>) so the compiler makes an arbitrary choice of which path to use</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>